<!--{__NOLAYOUT__}-->
{include file="../application/admin/view/template/header.html" /}
<style>
    #container {
        margin: auto;
        margin-top: 10px;
        width: 95%;
        /*text-align: center;*/
        /*border: 1px solid gainsboro;*/
    }
    form {
        margin-top: 15px;
        /*padding-right: 30px;*/
    }
</style>
<div id="container">
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label" >用户头像</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn layui-btn-primary" id="test1">
                <i class="layui-icon">&#xe64a;</i>选择头像
            </button>
            <input type="hidden" name="imgurl">
        </div>
        <div class="layui-input-block">
            <img id="upload-img" src="/uploads/admin/avatar/{$head_img}" style="margin: 5px 0 5px 0;width: 100px;height: 100px;border: 1px solid">
        </div>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="ListAction">
                <i class="layui-icon">&#xe67c;</i>修改头像
            </button>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">修改密码</label>
        <div class="layui-input-inline">
            <input type="password" name="change_pass"   placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">为空则不修改</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-inline">
            <input type="password" name="rchange_pass"  placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">与上方密码输入一致</div>
    </div>
        <h1>公共字段 --<span style="font-size: 12pt"> 由数据库设置的字段自动生成</span></h1>
    <div style="border: 1px dashed; margin: 10px 0; padding: 10px 0">
    {foreach $form as $v}
    {if $v.Field=='user_id'}
    <?php continue;?>
    {/if}
    <div class="layui-form-item">
        <label class="layui-form-label">{$v.Comment}</label>
        <div class="layui-input-inline">
            {if $profileData!=null}
            {if $v.Null=='NO'}
            <input type="text" name="{$v.Field}" required lay-verify="required" value='{$profileData[$v.Field]}'  placeholder="请输入{$v.Comment}" autocomplete="off" class="layui-input">
            {/if}
            <input type="text" name="{$v.Field}" value='{$profileData[$v.Field]}'  placeholder="请输入{$v.Comment}" autocomplete="off" class="layui-input">
            {else /}
            {if $v.Null=='NO'}
            <input type="text" name="{$v.Field}" required lay-verify="required" value="" placeholder="请输入{$v.Comment}" autocomplete="off" class="layui-input">
            {/if}
            <input type="text" name="{$v.Field}" value="" placeholder="请输入{$v.Comment}" autocomplete="off" class="layui-input">
            {/if}
        </div>
        {if $v.Null=='NO'}
        <div style="color: red;" class="layui-form-mid ">*必填</div>
        {/if}
    </div>
    {/foreach}
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">保存</button>
        </div>
    </div>
</form>
</div>
<script>
    //Demo
    layui.use(['form','upload'], function(){
        var form = layui.form
            ,  upload=layui.upload;

        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '/admin/upload/headUpload' //上传接口
            ,auto: false //选择文件后不自动上传
            ,bindAction: '#ListAction' //指向一个按钮触发上传
            //预读本地文件
            ,choose:function (obj) {
                obj.preview(function (index,file,result) {
                    $('#upload-img').attr('src',result);
                });
            }
            ,done: function(res){
                $('input[name="imgurl"]').val(res.data);
                layer.msg('上传成功', {icon: 1,anim:5,time: 2000});
            }
            ,error: function(){
                //请求异常回调
            }
        });

        //监听提交
        form.on('submit(formDemo)', function(data){
            if (data.field.change_pass != data.field.rchange_pass) {
                layer.msg('两次密码不一样', {icon: 2,anim:6,time: 2000});
                return false;
            }
            console.log(data.field);
            $.post("/admin/user/profile", data.field, function (result) {
                layer.msg(result.msg, {icon: 1,anim:5,time: 2000});

            });
            return false;
        });
    });
</script>